package com.bwie.controller;

import com.bwie.pojo.Galldate;
import com.bwie.pojo.Gallery;
import com.bwie.pojo.Subscribe;
import com.bwie.service.GalleryService;
import com.bwie.service.SubscribeService;
import com.bwie.service.UserOpenFig;

import com.bwie.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * TODO
 *
 * @Description
 * @Author 36167
 * @Date 2025/3/6 9:43
 **/

@RestController
@RequestMapping("/gall")
public class GalleryController {

    @Autowired
    private GalleryService galleryService;

    @Autowired
    private SubscribeService subscribeService;

    @Autowired
    private UserOpenFig userOpenFig;


    @PostMapping("/upload")
    public R upload(@RequestParam("file")MultipartFile file){
      return galleryService.upload(file);
    }

    @GetMapping("/list")
    public R list(){
        List<Gallery> list = galleryService.list1();
        return R.OK(list);
    }


  
    @GetMapping("/list1")
    private R list1(){
        List<Subscribe> list = subscribeService.list(null);
        return R.OK(list);
    }

    @GetMapping("/showdate")
    public R showdate(Integer gid){
       List<Galldate> list= galleryService.showdate(gid);
       return R.OK(list);
    }

    @PostMapping("/subadd")
    public R subadd(@RequestBody Subscribe subscribe){
     int i= subscribeService.subadd(subscribe);
     return i>0?R.OK():R.ERROR(500,"添加失败");
    }


    @PostMapping("/show/{uid}")
    public R show(@PathVariable Integer uid){
      return R.OK(userOpenFig.show(uid)) ;
    }


    @DeleteMapping("/delByid")
    public R delByid( String id){
         return subscribeService.delByid(id);
    }
}
